from config import sleep, driver, wait
import logging

class Steps:

    def __init__(self):
        self._steps = dict()


    def step(self, type:str):
        def outwrapper(func):
            def wrapper(*args, **kwargs):
                print("enter {}()".format(func.__name__))
                return func(*args, **kwargs)
            self._steps[type] = func
            logging.debug(self._steps)
            return wrapper
        return outwrapper
        

    def set_wait(self, wait:wait) -> None:
        self._wait = wait

    def run(self, steps:dict, driver:driver):
        for step in steps:
            type = step['type']
            logging.info(type)
            sleep(0.5)
            try:
                if type.startswith('wait'):
                    self._steps[type](self._wait, step)
                else:
                    self._steps[type](driver, step)
            except:
                logging.error(step)
                raise Exception()

        
